package com.itheima.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.BlackList;
import com.itheima.domain.UserInfo;
import com.itheima.mapper.BlackListMapper;
import com.itheima.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Resource
    private UserInfoMapper userInfoMapper;

    @Resource
    private BlackListMapper blackListMapper;

    /**
     * 黑名单查询
     *
     * @param page
     * @param size
     * @return
     */
    @Override
    public IPage getPage(Long userId, int page, int size) {
        Page pageInfo = new Page<>(page, size);
        IPage<UserInfo> newPage = userInfoMapper.getPage(pageInfo, userId);
        return newPage;
    }

    /**
     * 移除黑名单
     *
     * @param userId
     * @param uid
     */
    @Override
    public void deleteBlackList(Long userId, Long uid) {
        LambdaQueryWrapper<BlackList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BlackList::getUserId, userId);
        queryWrapper.eq(BlackList::getBlackUserId, uid);
        blackListMapper.delete(queryWrapper);
    }

}
